package com.example.plugin;

import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

/**
 * @author zy
 * @version V1.0
 * @description: TODO
 * @date 2020/10/19 15:02
 */
public class ButtonActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * 生命周期等方法正常走
     *
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //不处理资源文件的情况下只能在代码中添加控件，资源文件不能用.
        FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.setBackgroundColor(Color.WHITE);
        FrameLayout.LayoutParams layoutParams =
                new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.TOP);
        Button button = new Button(this);
        button.setText("我是插件Activity,我是代码布局，没有资源,再点我启动第二个");
        button.setTextColor(Color.GREEN);
        button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        button.setBackgroundColor(Color.RED);
        button.setOnClickListener(this);
        frameLayout.addView(button, layoutParams);
        setContentView(frameLayout);
    }


    @Override
    public void onClick(View v) {
        startActivity(new Intent(this, ImageActivity.class));
    }
}
